feat(tron-wallet-snap): route asset reads through Core AssetsController - #127
feat(tron-wallet-snap): route asset reads through Core AssetsController#127ulissesferreira wants to merge 5 commits into
Conversation
bfa488d to
327dfab
Compare
6587ae2 to
9428a52
Compare
6769ec9 to
4d766ab
Compare
9428a52 to
489bab0
Compare
|
@cursoragent rebase with latest main |
|
Rebased What happened during rebase:
Result: 8 commits ahead of |
4d766ab to
af82730
Compare
dbfa825 to
703eabc
Compare
|
@cursoragent make sure the CI is green |
There was a problem hiding this comment.
This is how simple fetching assets will be. All calls are basically direct AssetsController calls and then, for now, we map the structure of it to minimize the amount of changes in the repository. In a future PR we will want to remove the mapping and use the structure from the AssetsController. One of the methods also returns a dictionary, purposefully, which we will refactor the existing codebase to use as well because that is the idiomatic way to do things, if you fetch by a collection of IDs it only makes sense you get them back in an easy to access way.
| SNAPS_ASSETS_MIGRATION_FLAG_KEYS.tron, | ||
| ); | ||
| return parseSnapsAssetsMigrationStage(flagValue); | ||
| } |
There was a problem hiding this comment.
We use the function from AssetsController to see which stage of the migration we are on and we simply read the feature flags from the shared RemoteFeatureFlagsProvider
5fdb1d9 to
703eabc
Compare
| "AssetsController:getAccountAssetsByIDs", | ||
| "AssetsController:getAccountAssetsByScope" | ||
| "AssetsController:getAccountAssetsByScope", | ||
| "RemoteFeatureFlagController:getState" |
There was a problem hiding this comment.
Just a formatting fix
| rawAmount: amount, | ||
| uiAmount: toUiAmount(amount, decimals).toString(), | ||
| iconUrl, | ||
| } as AssetEntity; |
There was a problem hiding this comment.
For now this is needed because we haven't aligned all assetType from all different places
There was a problem hiding this comment.
On this file you can see the advantage of using the different adapters. Either we route operations to one or the other.
d163e9c to
0bdab3a
Compare
There was a problem hiding this comment.
Only a rename
9c70ee3 to
a793675
Compare
Match other snaps by listing @metamask/utils under devDependencies so import-x/no-extraneous-dependencies stays clean without a production dependency. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Remove stale tron-wallet-snap import-x/no-extraneous-dependencies suppressions now that @metamask/utils is declared. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
…ccountAssets Inject ConfigProvider into SnapAssetsAdapter, fold essential-asset synthesis into getAccountAssets / getAccountAssetsByScope, and update keyring callers to use getAccountAssets instead of getByKeyringAccountId. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
a793675 to
99fa147
Compare
There was a problem hiding this comment.
We were importing the configProvider directly from context.ts, which is possible to do, but we want to use dependency injection for more organized code and easier testing
Add CoreAssetsAdapter and mapControllerAsset, and route fungible asset reads through Core when the Tron assets migration flag is active. Reads stay on the Snap adapter while migration is off. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
99fa147 to
00333d9
Compare
| this.cacheTtlsMilliseconds = this.#snapAdapter.cacheTtlsMilliseconds; | ||
| } | ||
|
|
||
| async #getAssetsMigrationStage(): Promise<SnapsAssetsMigrationStage> { |
There was a problem hiding this comment.
nit: but might simplify a bit if we return a boolean from this method, instead of checking every time if (migrationStage === SnapsAssetsMigrationStage.Off)
| }) { | ||
| this.#remoteFeatureFlagsProvider = remoteFeatureFlagsProvider; | ||
|
|
||
| this.#snapAdapter = new SnapAssetsAdapter({ |
There was a problem hiding this comment.
it seems like we pass all the dependencies just to instantiate SnapAssetsAdapter, maybe better to instantiate SnapAssetsAdapter outside of AssetsService and simplify this class wdyt?
There was a problem hiding this comment.
Very good point and that is the correct way to implement the Adapter pattern. What is done there is not right. Will change it ✏️
| snapClient, | ||
| configProvider, | ||
| }); | ||
| this.#coreAdapter = new CoreAssetsAdapter({ |
8d32e80 to
b472e36
Compare


Summary
getAccountAssetByID,getAccountAssetsByIDs,getAccountAssetsByScopeandgetAccountAssetsJira
Test plan
yarn workspace @metamask/tron-wallet-snap run jest --no-coverage src/services/assets/